package com.itstyle.seckill.common.filter;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * *
 *
 * @author yangxiaogen
 * @date 2022/3/21 23:05
 */
@Component
public class CheckInDataFilter implements Filter {

    private FilterConfig filterConfig;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

        final HttpServletRequest request = (HttpServletRequest) req;
        final HttpServletResponse response = (HttpServletResponse) res;

        String seckillId = request.getParameter("seckillId");

        if (StringUtils.isBlank(seckillId)) {
            //throw new RuntimeException("请求参数 seckillId 不能为空!!!!!!");
        }

        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
